/*
  Copyright 2009 Smart Enterprise Solution Corp.
  Email: contact@ses.vn - Website: http://www.ses.vn
  KimNgan Project.
*/
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Data.SqlClient;
using VINETLIFE.DO;
/// <summary>
/// Summary description for cmsCustomerOtherAccountDAL
/// </summary>
namespace VINETLIFE.DAL
{

    public class cmsCustomerOtherAccountDAL : BaseDAL
    {
        #region Private Variables

        #endregion

        #region Public Constructors
        public cmsCustomerOtherAccountDAL()
        {
            //
            // TODO: Add constructor logic here
            //

        }
        #endregion



        #region Public Methods
        public int Insert(cmsCustomerOtherAccountDO objcmsCustomerOtherAccountDO)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsCustomerOtherAccount_Insert";
            SqlParameter Sqlparam;

            Sqlparam = new SqlParameter("@Username", SqlDbType.NVarChar);
            Sqlparam.Value = objcmsCustomerOtherAccountDO.Username;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@CustomerId", SqlDbType.Int);
            Sqlparam.Value = objcmsCustomerOtherAccountDO.CustomerId;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@AccountType", SqlDbType.NVarChar);
            Sqlparam.Value = objcmsCustomerOtherAccountDO.AccountType;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@AccountText", SqlDbType.NVarChar);
            Sqlparam.Value = objcmsCustomerOtherAccountDO.AccountText;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@AccountValue", SqlDbType.NVarChar);
            Sqlparam.Value = objcmsCustomerOtherAccountDO.AccountValue;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@CreatedDate", SqlDbType.DateTime);
            Sqlparam.Value = objcmsCustomerOtherAccountDO.CreatedDate;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@CreatedById", SqlDbType.Int);
            Sqlparam.Value = objcmsCustomerOtherAccountDO.CreatedById;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@LastModifiedById", SqlDbType.Int);
            Sqlparam.Value = objcmsCustomerOtherAccountDO.LastModifiedById;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@LastSaveDate", SqlDbType.DateTime);
            Sqlparam.Value = objcmsCustomerOtherAccountDO.LastSaveDate;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@Active", SqlDbType.Bit);
            Sqlparam.Value = objcmsCustomerOtherAccountDO.Active;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@ID", SqlDbType.Int);
            Sqlparam.Direction = ParameterDirection.ReturnValue;
            Sqlcomm.Parameters.Add(Sqlparam);


            int result = base.ExecuteNoneQuery(Sqlcomm);

            if (!Convert.IsDBNull(Sqlcomm.Parameters["@ID"]))
                result = Convert.ToInt32(Sqlcomm.Parameters["@ID"].Value);

            return result;
        }

        public int Update(cmsCustomerOtherAccountDO objcmsCustomerOtherAccountDO)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsCustomerOtherAccount_UpdateByPK";
            SqlParameter Sqlparam;

            Sqlparam = new SqlParameter("@ID", SqlDbType.Int);
            Sqlparam.Value = objcmsCustomerOtherAccountDO.ID;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@Username", SqlDbType.NVarChar);
            Sqlparam.Value = objcmsCustomerOtherAccountDO.Username;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@CustomerId", SqlDbType.Int);
            Sqlparam.Value = objcmsCustomerOtherAccountDO.CustomerId;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@AccountType", SqlDbType.NVarChar);
            Sqlparam.Value = objcmsCustomerOtherAccountDO.AccountType;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@AccountText", SqlDbType.NVarChar);
            Sqlparam.Value = objcmsCustomerOtherAccountDO.AccountText;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@AccountValue", SqlDbType.NVarChar);
            Sqlparam.Value = objcmsCustomerOtherAccountDO.AccountValue;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@CreatedDate", SqlDbType.DateTime);
            Sqlparam.Value = objcmsCustomerOtherAccountDO.CreatedDate;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@CreatedById", SqlDbType.Int);
            Sqlparam.Value = objcmsCustomerOtherAccountDO.CreatedById;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@LastModifiedById", SqlDbType.Int);
            Sqlparam.Value = objcmsCustomerOtherAccountDO.LastModifiedById;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@LastSaveDate", SqlDbType.DateTime);
            Sqlparam.Value = objcmsCustomerOtherAccountDO.LastSaveDate;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@Active", SqlDbType.Bit);
            Sqlparam.Value = objcmsCustomerOtherAccountDO.Active;
            Sqlcomm.Parameters.Add(Sqlparam);



            Sqlparam = new SqlParameter("@ErrorCode", SqlDbType.Int);
            Sqlparam.Direction = ParameterDirection.ReturnValue;
            Sqlcomm.Parameters.Add(Sqlparam);

            int result = base.ExecuteNoneQuery(Sqlcomm);

            if (!Convert.IsDBNull(Sqlcomm.Parameters["@ErrorCode"]))
                result = Convert.ToInt32(Sqlcomm.Parameters["@ErrorCode"].Value);

            return result;


        }

        public int Delete(cmsCustomerOtherAccountDO objcmsCustomerOtherAccountDO)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsCustomerOtherAccount_DeleteByPK";
            SqlParameter Sqlparam;


            Sqlparam = new SqlParameter("@ID", SqlDbType.Int);
            Sqlparam.Value = objcmsCustomerOtherAccountDO.ID;
            Sqlcomm.Parameters.Add(Sqlparam);



            int result = base.ExecuteNoneQuery(Sqlcomm);
            return result;
        }

        public int DeleteAll()
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsCustomerOtherAccount_DeleteAll";

            int result = base.ExecuteNoneQuery(Sqlcomm);
            return result;
        }
        public int UpdateActive()
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "cmsCustomerOtherAccount_UpdateActive";

            int result = base.ExecuteNoneQuery(Sqlcomm);
            return result;
        }
        public DataTable SelectAccountType(string AccountType)
        {
            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "cmsCustomerOtherAccount_SelectType";
            SqlParameter Sqlparam;


            Sqlparam = new SqlParameter("@AccountType", SqlDbType.Int);
            Sqlparam.Value = AccountType;
            Sqlcomm.Parameters.Add(Sqlparam);

            DataSet ds = base.GetDataSet(Sqlcomm);
            DataTable dt = null;

            if (ds != null && ds.Tables.Count > 0)
            {
                dt = ds.Tables[0];

            }
            return dt;
        }
        public cmsCustomerOtherAccountDO Select(cmsCustomerOtherAccountDO objcmsCustomerOtherAccountDO)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsCustomerOtherAccount_GetByPK";
            SqlParameter Sqlparam;


            Sqlparam = new SqlParameter("@ID", SqlDbType.Int);
            Sqlparam.Value = objcmsCustomerOtherAccountDO.ID;
            Sqlcomm.Parameters.Add(Sqlparam);



            DataSet ds = base.GetDataSet(Sqlcomm);
            DataRow dr = null;
            if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                dr = ds.Tables[0].Rows[0];
                if (!Convert.IsDBNull(dr["ID"]))
                    objcmsCustomerOtherAccountDO.ID = Convert.ToInt32(dr["ID"]);
                if (!Convert.IsDBNull(dr["Username"]))
                    objcmsCustomerOtherAccountDO.Username = Convert.ToString(dr["Username"]);
                if (!Convert.IsDBNull(dr["CustomerId"]))
                    objcmsCustomerOtherAccountDO.CustomerId = Convert.ToInt32(dr["CustomerId"]);
                if (!Convert.IsDBNull(dr["AccountType"]))
                    objcmsCustomerOtherAccountDO.AccountType = Convert.ToString(dr["AccountType"]);
                if (!Convert.IsDBNull(dr["AccountText"]))
                    objcmsCustomerOtherAccountDO.AccountText = Convert.ToString(dr["AccountText"]);
                if (!Convert.IsDBNull(dr["AccountValue"]))
                    objcmsCustomerOtherAccountDO.AccountValue = Convert.ToString(dr["AccountValue"]);
                if (!Convert.IsDBNull(dr["CreatedDate"]))
                    objcmsCustomerOtherAccountDO.CreatedDate = Convert.ToDateTime(dr["CreatedDate"]);
                if (!Convert.IsDBNull(dr["CreatedById"]))
                    objcmsCustomerOtherAccountDO.CreatedById = Convert.ToInt32(dr["CreatedById"]);
                if (!Convert.IsDBNull(dr["LastModifiedById"]))
                    objcmsCustomerOtherAccountDO.LastModifiedById = Convert.ToInt32(dr["LastModifiedById"]);
                if (!Convert.IsDBNull(dr["LastSaveDate"]))
                    objcmsCustomerOtherAccountDO.LastSaveDate = Convert.ToDateTime(dr["LastSaveDate"]);
                if (!Convert.IsDBNull(dr["Active"]))
                    objcmsCustomerOtherAccountDO.Active = Convert.ToBoolean(dr["Active"]);

            }
            return objcmsCustomerOtherAccountDO;
        }

        public ArrayList SelectAll1()
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsCustomerOtherAccount_GetAll";

            DataSet ds = base.GetDataSet(Sqlcomm);
            DataTable dt = null;
            ArrayList arrcmsCustomerOtherAccountDO = new ArrayList();
            if (ds != null && ds.Tables.Count > 0)
            {
                dt = ds.Tables[0];
                foreach (DataRow dr in dt.Rows)
                {
                    cmsCustomerOtherAccountDO objcmsCustomerOtherAccountDO = new cmsCustomerOtherAccountDO();
                    if (!Convert.IsDBNull(dr["ID"]))
                        objcmsCustomerOtherAccountDO.ID = Convert.ToInt32(dr["ID"]);
                    if (!Convert.IsDBNull(dr["Username"]))
                        objcmsCustomerOtherAccountDO.Username = Convert.ToString(dr["Username"]);
                    if (!Convert.IsDBNull(dr["CustomerId"]))
                        objcmsCustomerOtherAccountDO.CustomerId = Convert.ToInt32(dr["CustomerId"]);
                    if (!Convert.IsDBNull(dr["AccountType"]))
                        objcmsCustomerOtherAccountDO.AccountType = Convert.ToString(dr["AccountType"]);
                    if (!Convert.IsDBNull(dr["AccountText"]))
                        objcmsCustomerOtherAccountDO.AccountText = Convert.ToString(dr["AccountText"]);
                    if (!Convert.IsDBNull(dr["AccountValue"]))
                        objcmsCustomerOtherAccountDO.AccountValue = Convert.ToString(dr["AccountValue"]);
                    if (!Convert.IsDBNull(dr["CreatedDate"]))
                        objcmsCustomerOtherAccountDO.CreatedDate = Convert.ToDateTime(dr["CreatedDate"]);
                    if (!Convert.IsDBNull(dr["CreatedById"]))
                        objcmsCustomerOtherAccountDO.CreatedById = Convert.ToInt32(dr["CreatedById"]);
                    if (!Convert.IsDBNull(dr["LastModifiedById"]))
                        objcmsCustomerOtherAccountDO.LastModifiedById = Convert.ToInt32(dr["LastModifiedById"]);
                    if (!Convert.IsDBNull(dr["LastSaveDate"]))
                        objcmsCustomerOtherAccountDO.LastSaveDate = Convert.ToDateTime(dr["LastSaveDate"]);
                    if (!Convert.IsDBNull(dr["Active"]))
                        objcmsCustomerOtherAccountDO.Active = Convert.ToBoolean(dr["Active"]);
                    arrcmsCustomerOtherAccountDO.Add(objcmsCustomerOtherAccountDO);
                }
            }
            return arrcmsCustomerOtherAccountDO;
        }

        public DataTable SelectAll()
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsCustomerOtherAccount_GetAll";

            DataSet ds = base.GetDataSet(Sqlcomm);
            DataTable dt = null;

            if (ds != null && ds.Tables.Count > 0)
            {
                dt = ds.Tables[0];

            }
            return dt;
        }


        #endregion

    }

}
